<template>
  <div class="ui-renderer">
    <div class="component-header">
      <h2 class="component-title">{{ componentConfig.title }}</h2>
      <el-tag type="primary" class="component-type-tag">
        {{ getComponentTypeName(componentConfig.component_type) }}
      </el-tag>
    </div>
    
    <component 
      :is="currentComponent" 
      :config="componentConfig"
      class="component-content"
    />
  </div>
</template>

<script setup>
import { computed } from 'vue'
import DashboardComponent from './DashboardComponent.vue'
import FormComponent from './FormComponent.vue'

const props = defineProps({
  componentConfig: {
    type: Object,
    required: true
  }
})

const componentMap = {
  dashboard: DashboardComponent,
  form: FormComponent
}

const currentComponent = computed(() => {
  return componentMap[props.componentConfig.component_type]
})

const getComponentTypeName = (type) => {
  const typeNames = {
    dashboard: '数据面板',
    form: '表单'
  }
  return typeNames[type] || type
}
</script>

<style scoped>
.ui-renderer {
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.component-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
  background: #fafafa;
}

.component-title {
  margin: 0;
  font-size: 18px;
  color: #1d2129;
  font-weight: 600;
}

.component-type-tag {
  font-size: 12px;
}

.component-content {
  padding: 20px;
}
</style>